<!DOCTYPE html>
<html lang="zh-cn">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>room</title>
    <link rel="stylesheet" href="../../../static/layer/css/layui.css" media="all"/>
    <link rel="stylesheet" href="../../../static/css/font-awesome.min.css" media="all">
    <style>
        /* 是否开启样式 */
        .layui-form-switch {
            width: 54px;
            margin-top: 0;
        }

        .layui-form-switch i {
            top: 2px;
        }

        /* 导航样式 */
        .layui-tab {
            margin: 0;
        }

        .layui-tab-title {
            height: auto;
        }

        .layui-tab-title li {
            padding: 0;
        }

        .layui-tab-card > .layui-tab-title .layui-tab-bar {
            height: 60px;
            line-height: 60px;
        }

        .layui-nav .layui-nav-item a {
            color: #666666;
        }

        .layui-nav .layui-nav-item a:hover {
            color: #000000;
        }

        .layui-tab-card > .layui-tab-title .layui-this {
            background-color: transparent;
        }

        .layui-tab-card > .layui-tab-title .layui-this a {
            color: #000000;
        }

        .layui-tab-card > .layui-tab-title .layui-this::after {
            content: '';
            bottom: 0;
            width: 100%;
            position: absolute;
            left: 0;
            top: 55px;
            height: 6px;
            background-color: #5FB878;
            transition: all .2s;
            -webkit-transition: all .2s;
        }
    </style>
</head>
<body>
<div class="layui-tab layui-tab-card">
    <ul class="layui-nav layui-tab-title layui-bg-gray">
    </ul>
</div>
<div style="padding: 20px; position: relative;">
    <div class="operateTable">
        名称：
        <br>
        项目类型管理
    </div>
    <div class="operateTable" style="position: absolute; top: 20px; right:20px;">
        <button class="layui-btn" data-type="addBuilding"><i class="layui-icon"></i> 新增项目类型</button>
    </div>
    <table class="layui-table" id='roomTable' lay-filter="business">
    </table>
    <script type="text/html" id="barDemo">
        {{# var type = d.ID }}
        {{# if (type != 'ee96f524afbb49caa94d6342983d91a0' && type != '24132c9c8ba543deadb198e6b982dba9'&& type != 'cheku'&& type != 'guanggaopai'&& type != 'pingfang'&& type != 'chucangshi' ){ }}
        <a class="layui-btn layui-btn-mini" lay-event="edit">编辑</a>
        <a class="layui-btn layui-btn-danger layui-btn-mini" lay-event="del">删除</a>
        {{# } else{ }}
        {{# } }}
    </script>
</div>
<script type="text/javascript" src="../../../static/layer/layui.js"></script>
<script>
    var table;
    layui.use(['jquery', 'table', 'form', 'layer', 'element'], function () {
        table = layui.table;
        var $ = layui.jquery,
            element = layui.element, //导航的hover效果、二级菜单等功能，需要依赖element模块
            form = layui.form;
        var type;
        //监听工具条
        table.render({
            elem: '#roomTable',
            url: '/dictionary/jsontype/',
            page: false,
            limit: 20,
            height: 400,
            id:'roomTableid',
            cols: [[
                 {field: 'NAME', title: '名称',align: 'center', width: 360}
                , {fixed: 'right', width: 360, align: 'center', toolbar: '#barDemo'}
            ]]
        });
        //刷新表单
        function reloadtable() {
            table.reload('roomTableid');
        }
        table.on('tool(business)', function (obj) {
            var data = obj.data;
            if (obj.event === 'del') {

                layer.confirm('确认删除 ' + data.NAME + ' 吗', {offset: '150px'}, function (index) {
//                    obj.del();
                    layer.close(index);
                    $.ajax({
                        url: "/dictionary/deletetype",
                        data: {ID: data.ID, IS_DEL: 1},
                        dataType: "json",
                        type: "post",
                        async: false,
                        success: function (res) {

                            if (res.errcode === "0") {

                                reload();    // 表格刷新
                                layer.msg(data.NAME + " 已删除", {offset: '150px'});   // 弹出删除成功
                            } else if (res.errcode === "1") {
                                layer.msg(res.errmsg, function () {
                                });
                            }
                        },
                        error: function (XMLHttpRequest, textStatus, errorThrown) {
                            console.error(XMLHttpRequest.status);
                            console.error(XMLHttpRequest.readyState);
                            console.error(textStatus);
                        }
                    });
                    reloadtable();
                });
            } else if (obj.event === 'edit') {
                    layer.open({
                        type: 2,
                        title: "编辑 " + data.NAME + " 类型",
                        shadeClose: false,
                        shade: [0.3],
                        maxmin: true, //开启最大化最小化按钮
                        area: ['900px', '90%'],
                        scrollbar: false, //屏蔽滚动条
                        content: 'projecttypeadd.html?type=edit&id=' + data.ID
                    });
                }
        });
        var active = {
            changeBusiness: function (obj) { //获取选中数据
                reloadTable();
            },
            reload: function () {
               var name = $('#filter-id').val();
                reloadTable(name);
                table.reload('roomTable', {});
            },
            addBuilding: function () {
                layer.open({
                    type: 2,
                    title: '新增项目类型',
                    shadeClose: false,
                    shade: [0.3],
                    maxmin: true, //开启最大化最小化按钮
                    area: ['500px', '70%'],
                    scrollbar: false, //屏蔽滚动条
                    content: 'projecttypeadd.html?type=add'
                });
            },
        };
        function reloadTable(name) {
            var data = {};
            data.BUILDING_ID = buildingId;
            if (!!name) {
                data.ROOM_NAME = name;
            }
            table.render({
                elem: '#roomTable',
                url: '/dictionary/list_type/',
                page: true,
                limit: 20,
                height: 400,
                where: data,
                cols: [[
                    {field: '', fixed: true}
                    , {field: 'ROOM_NAME', title: '名称', width: 84}
                    , {field: 'ROOM_TYPE', title: '项目类型', width: 100}
                    , {fixed: 'right', width: 300, align: 'center', toolbar: '#barDemo'}
                ]]
            });
        }
        $('.operateTable .layui-btn').on('click', function () {
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });
    });

    function reload() {
        table.render({
            elem: '#roomTable',
            url: '/dictionary/jsontype/',
            page: false,
            limit: 20,
            height: 400,
            cols: [[
                {field: '', fixed: true}
                , {field: 'NAME', title: '名称',align: 'center', width: 360}
                , {fixed: 'right', width: 360, align: 'center', toolbar: '#barDemo'}
            ]]
        });
    }

</script>
</body>
</html>